<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{% $title %}</title>
<script language="javascript" type="text/javascript"
	src="js/default/jquery-1.9.1.min.js"> </script>
<script language="javascript" type="text/javascript"
	src="include/tinymce/tiny_mce.js"> </script>
<script language="javascript" type="text/javascript"
	src="js/default/tinymce_kcfinder_config.js"></script>
<script language="javascript" type="text/javascript"
	src="include/My97DatePicker/WdatePicker.js"></script>
<script language="javascript" type="text/javascript">
$=jQuery;
$(document).ready(function(){
	$("#title_exists").hide();
    $("#external_link").hide();
	$("#is_top_time").hide();
	$("#custom_top_time").hide();
	$("#show_picture").hide();
	 $("#picture_operator").hide();

});

function changeSelect(){
	choice=$("#is_top_time").val();
	if(choice=='5'){
		showCustomTopTimeSelect();
	}
	else{
		hideCustomTopTimeSelect();
		}
}
 function showTopTimeSelect(){
	 $("#is_top_time").show();
 }
 function hideTopTimeSelect(){
	 $("#is_top_time").hide();
 }
 function showCustomTopTimeSelect(){
	 $("#custom_top_time").show();
 }
 function hideCustomTopTimeSelect(){
	 $("#custom_top_time").hide();
 }
 function showExternalLinkChange(){
	 if($("#links").is(':checked')){
	 $("#external_link").show();
	 } 
	 else{
	 $("#external_links").val(""); 
	 $("#external_link").hide();
 }
 }
 
 function changeContent(){
	 var link=$("#external_links").val();
	 if(link!=""){
		 var pattern =/^http(.*)/;
		 if(!(pattern.test(link))){
			 link="http:\/\/"+link;
			 $("#external_links").val(link);
		} 
		 }
 }
 function openKCFinder_singleFile() {
	    window.KCFinder = {};
	    window.KCFinder.callBack = function(url) {
	        // Actions with url parameter here
	        $("#picture").val(url);
	        $("#show_picture").attr('src',url);
	        $("#show_picture").show();
	        $("#picture_operator").show();
	        $("#insert_pic").hide();
	        $("#picture_show").css("margin-top","45px");
	        $("#thumbnail").css("margin-top","2px");
	   	    window.KCFinder = null;
	    };
	    window.open('include/kcfinder/browse.php?type=image','newwindow','height=600,width=600,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
	}
 function removePicture(){
	  $("#picture").val("");
	  $("#show_picture").hide();
	  $("#picture_operator").hide();
	  $("#picture_show").css("margin-top","0px");
	  $("#thumbnail").css("margin-top","0px");
	  $("#insert_pic").show();
 }
 
 function showBigPicture(){
	 window.open($("#picture").val(),'newwindow','height=600,width=600,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
 }
 function cropPicture(){
	 image_path=escape($("#picture").val());
	 window.open("crop.php?image="+image_path,'newwindow','height=450,width=600,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
 }
function checkSubmit()
{
	if($("#title").val()=='')
	{
		alert('文章标题不能为空！');
		return false;
	}
	if($("#title_exist").val()!=""){
		alert("请修改重复的文章标题！");
		return false;
	}
	if($("#links").is(':checked')&&$("#external_links").val()==""){
		alert("请输入外部链接！");
		return false;
	}
	if($("#from").val()==0)
	{
		alert('请输入文章来源！');
		return false;
	}
	if($("#main_channel").val()==0)
	{
		alert('请选择文章的主栏目！');
		return false;
	}
		if(($("#is_top_time").val()=='5')){
		if($("#custom_top_time").val()==""){
			alert('请选择自定义置顶到期时间！');
			return false;
		}
		else{
		date1=new Date($("#custom_top_time").val().replace(/-/g,"/"));
		date2=new Date($("#publish_time").val().replace(/-/g,"/"));
		if(date1<=date2){
		alert('自定义置顶到期时间必须大于发表时间！');
		return false;
		}
		}
	}
}
</script>
<style>
/*主体*/
html,body {
	width: 100%;
	height: 100%;
	font-family: "微软雅黑";
	font-size: 13px;
	margin:0px;
}

#main {
    padding-left:20px;
    padding-top:1px;
	border: 1px double #aaa;
}

.division {
	border: 1px dotted #aaa;
}
a{
   text-decoration: none;
}
div{
 background:#EEFFEE;
}
#title_exist{
 color: red;
}
.readonly{
  border:0;
  background:#EEFFEE;
}
.hide{
visibility: hidden;
}
#picture_show{
float:left;
}
#picture_operator{
list-style-type: none;
display: inline-block;
margin:0px;
padding-left:8px;
}
#show_picture{
border:0px;
}
#submit{
 padding-top:5px;
  padding-bottom:5px; 
}
</style>
</head>
<body>
	<div id="main">
		<form action="article_add_save.php" method="post" id="forms" onSubmit="return checkSubmit()">
			<span><img alt="必填" title="必填" src="images/article/flag.png" width="10px" height="10px">
			文章标题：&nbsp;&nbsp;</span> <input id="title" name="title" type="text"
				size="70" maxlength="100"/><input type="checkbox"	id="links" name="links[]" onclick="showExternalLinkChange();"><span>外部链接</span>
				<div id="title_exists"><input id="title_exist" value="" readonly="readonly" class="readonly" size="50"/></div>
				<div id="external_link">
				<div class="division"></div>
			<span><img alt="必填" title="必填" src="images/article/flag.png" width="10px" height="10px">外部链接url:&nbsp;&nbsp;</span><input name="external_links" id="external_links" type="text" size="50" onchange="changeContent();" />
				</div>
			<div class="division"></div>
			<span><img alt="必填" title="必填" src="images/article/flag.png" width="10px" height="10px">
			文章来源：&nbsp;&nbsp;</span> <input name="from" id="from" type="text"
				size="20" />
			<div class="division"></div>
			<input name="writer" id="writer" type="hidden" value="{% $writer %}" /> 
			<img alt="必填" title="必填" src="images/article/flag.png" width="10px" height="10px">
			<span>文章栏目：&nbsp;&nbsp;</span>
			<select name='main_channel' id='main_channel'>   
				<option value='0'>请选择栏目...</option>
				 {% $all_channel %}
			</select>
			<div class="division"></div>
			<div id="thumbnail">
			<span id="picture_show">缩略图：&nbsp;&nbsp;&nbsp;</span><input type="hidden" name="picture" id="picture"/>
			<a href="javascript:" onclick="openKCFinder_singleFile();" id="insert_pic">插入图片</a>
            &nbsp;&nbsp;<a href="javascript:void(0);" onclick="showBigPicture();"><img name="show_picture" id="show_picture" height="100px" alt="预览" title="点击查看大图"/></a>
            <ul id="picture_operator">
            <li id="modify_picture"><a href="javascript:" onclick="cropPicture();"><span>裁剪缩略图</span></a></li>
            <li class="hide">hidden</li>
            <li id="remove_picture"> <a href="javascript:" onclick="removePicture();"><span>删除缩略图</span></a></li>
            <li class="hide">hidden</li>
           </ul>
            </div>
            <div class="division"></div>
            <span>浏览次数：&nbsp;&nbsp;</span><input id="clicked_times" name="clicked_times" type="text"
				size="5" value="0"/>
				 <div class="division"></div>
			 <span>发表时间：&nbsp;&nbsp;</span><input name="publish_time" type="text"
				class="Wdate" value="{% $time %}" id="publish_time" onFocus="WdatePicker()">
			<div class="division"></div>
			<div id="is_top">
			<span>是否置顶：&nbsp;&nbsp;</span>
			<input type="radio" name="istop" id="istop" value="0" checked="checked" onclick="hideTopTimeSelect();hideCustomTopTimeSelect();"/><span>否</span>
			<input type="radio" name="istop" id="istop" value="1" onclick="showTopTimeSelect();changeSelect();"/><span>是</span>
            &nbsp;&nbsp;
            <select id="is_top_time" name="is_top_time" onchange="changeSelect();">
            <option value='0'>置顶一周</option>
			<option value='1'>置顶一个月</option>
			<option value='2'>置顶三个月</option>
			<option value='3'>置顶半年</option>
			<option value='4'>置顶一年</option>
			<option value='5'>自定义过期日期</option>
				</select>
			<input name="custom_top_time" type="text" class="Wdate"  id="custom_top_time" onFocus="WdatePicker()">
            </div>
            <div class="division"></div>
			<div id="content">文章内容：</div>
			<textarea name="article_content" editor_id="article_content" id="article_content" mce_editable="true"></textarea>
			 <div align="center" id="submit"><input type="submit" title="保存" name="submit" value="保存" /></div>
		   
		</form>
	</div>
</body>
</html>